<?php
class Mageex_AdvanceSeo_Model_Layer extends Mage_Catalog_Model_Layer
{

  	/**
     * @return $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection
  	 */
    public function getFilterableAttributes()
    {   
        $setIds = $this->_getSetIds();
        if (!$setIds) {
            $setIds = array();
        }
        /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection */
        $collection = Mage::getResourceModel('catalog/product_attribute_collection')
            ->setItemObjectClass('catalog/resource_eav_attribute');

        $collection->getSelect()->distinct(true);
        $collection
            ->setAttributeSetFilter($setIds)
            ->addStoreLabel(Mage::app()->getStore()->getId())
            ->setOrder('position', 'ASC');
        $collection = $this->_prepareAttributeCollection($collection);
        $collection->load();
        return $collection;
    }
    
    /**
     * 
     * @param $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
     * $return void
     */
    public function setProductCollection($collection) 
    {
      	$this->prepareProductCollection($collection);
      	$this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;     
    }
    
    /**
     * 
     * @param $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection
     * @return Mage_Catalog_Model_Layer
     */
    public function prepareProductCollection($collection)
    {
        $attributes = Mage::getSingleton('catalog/config')
            ->getProductAttributes();
            
        $collection->addAttributeToSelect($attributes)
            ->addMinimalPrice()
            ->addFinalPrice()
            ->addTaxPercents()
            //->addStoreFilter()
            ;
        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
        $collection->addUrlRewrite($this->getCurrentCategory()->getId());
		
        return $this;
    }        
}